package com.java.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * description:描述
 * author:作者
 * time:2020/12/7 16:11
 */
@Controller
public class UploadFileController {

    @RequestMapping("/uploadFile.do")
    public void uploadFile(MultipartFile uploadFile) throws IOException {
        String originalFilename = uploadFile.getOriginalFilename();
        String substring = originalFilename.substring(originalFilename.indexOf("."));
        String s = UUID.randomUUID().toString();
        String filename = s+substring;
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd\\HH\\mm\\ss");
        String basepath = simpleDateFormat.format(date);
        File file1 = new File("35e22z6886.wicp.vip:39534\\C:\\uploads\\"+basepath);
        if(!file1.exists()){
            file1.mkdirs();
        }
        String autoFile = "35e22z6886.wicp.vip:39534\\C:\\uploads\\"+basepath+"\\"+s+filename;
        uploadFile.transferTo(new File(autoFile));
    }
}
